<template>
	<div class="home">
    <nav-header></nav-header>
    <div class="home-main">
      <router-view/>
    </div>
	</div>
</template>
<script setup>
import {computed, ref} from "vue";
import {useRoute, useRouter} from "vue-router";
import {useStore} from "vuex";
import {clearSessionStorage} from "../../utils/commonScript";
import {getCookies, removeCookies} from "../../utils";
import NavHeader from "./nav-header.vue";



const router = useRouter()
const store = useStore()
const route = useRoute()

const defaultActive = ref('/')
defaultActive.value = route.path

const baseInfo = computed(() => {
  return store.state.baseInfo;
})


const updatePasswordRef = ref()

const open = () => {
    store.commit('setVipModel', true)
}
const updatePasswordHandle = () => {
	updatePasswordRef.value.init()
}
/**
 * 跳转
 * @param path
 */
const goLink = (path) => {
  router.push({
    path: path
  });
}

/**
 * 初始化
 * 刷新时存储相应的store
 */
const init = () => {
  const user = sessionStorage.getItem('baseInfo') ? JSON.parse(sessionStorage.getItem('baseInfo')) : {}
  if (user.id) {
    store.commit('setBaseInfo', user)
    store.commit('globalStore/setUserId', user.id);
	  store.dispatch('getUser')
  } else {
	  let token = getCookies()
	  if (token) {
		  store.dispatch('getUser')
	  } else {
		  clearSessionStorage();
		  goLink('/login');
	  }
  }
}
init();
</script>
<style lang="scss" scoped>
.home{
  height: 100%;
  display: flex;
  flex-direction: column;
  .home-main{
    background-color: #f5f5f5;
    padding: 10px;
    flex: 1;
    .el-container{
      height: 100%;
    }
  }
}
</style>
